package com.zkj.handler;

import com.zkj.exception.BaseException;
import com.zkj.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: zhangKaiJun
 * @createTime：2024/8/26
 * @description：
 */

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public Result handleException(BaseException e) {
        log.error("全局异常处理：{}", e);
        log.info("全局异常处理222：{} {}", e.getMessage(), e.getErrorCode());
        if(e.getErrorCode() == 0) {
            log.info("全局异常处理33");

            return Result.error(e.getMessage());
        } else {
            log.info("全局异常处理44");
            return Result.error(e.getMessage()).code(e.getErrorCode());
        }
    }
}
